# 水果清单

fruits = {'apple': 23,
          'banana': 24,
          'mango': 45,
          '哈密瓜': 89
          }

# 打印所有的水果
for key in fruits:
    print(f'水果是{key}')
# 找出最贵的水果
result = list(fruits.values())
print(result)
max_value = max(result)
print(max_value)
print('=================================================')

# 学生成绩

student = [
    {'name': '张三',
     'scores': {'语文': 359, '数学': 69, '英语': 10}
     },
    {'name': '李四',
     'scores': {'语文': 359, '数学': 69, '英语': 10}
     },
    {'name': '王五',
     'scores': {'语文': 68, '数学': 39, '英语': 120}
     }
]

# 计算每位学生的平均分
total_score = 0
for i in student:
    print(i)
    key_name = i.get('name')
    key_scores = i.get('scores')
    total_score = sum(key_scores.values())
    avg_score = total_score / len(key_scores)
    print("%s的平均分是%.2f" % (key_name, avg_score))

# 找出总分最高的学生
print('lllllllllllllllllllllllllllll')


# total_score1 = []
# for i in student:
#     print(i)
#     key_name = i.get('name')
#     key_scores =i.get('scores')
#     total_score1.append(sum(key_scores.values()))
#
# max_score = max(total_score1)
# print(max_score)


def find_best():  # 设置最高分
    best_score = 0
    best_name = []
    for key in student:
        total_score = 0
        total_score = sum(key['scores'].values())
        if total_score > best_score:
            best_name.append(key['name'])
            best_score = total_score

        elif total_score == best_score:
             best_name.append(key['name'])
    print(f"最高分是{best_score},有{best_name}")

find_best()
